package com.ruoyi.order.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.order.domain.ShoppingPurchase;
import com.ruoyi.order.service.IShoppingPurchaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 购买详情Controller
 * 
 * @author ruoyi
 * @date 2024-03-09
 */
@RestController
@RequestMapping("/order/order")
public class ShoppingPurchaseController extends BaseController
{
    @Autowired
    private IShoppingPurchaseService shoppingPurchaseService;

    /**
     * 查询购买详情列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ShoppingPurchase shoppingPurchase)
    {
        startPage();
        List<ShoppingPurchase> list = shoppingPurchaseService.selectShoppingPurchaseList(shoppingPurchase);
        return getDataTable(list);
    }

    /**
     * 导出购买详情列表
     */
    @Log(title = "购买详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShoppingPurchase shoppingPurchase)
    {
        List<ShoppingPurchase> list = shoppingPurchaseService.selectShoppingPurchaseList(shoppingPurchase);
        ExcelUtil<ShoppingPurchase> util = new ExcelUtil<ShoppingPurchase>(ShoppingPurchase.class);
        util.exportExcel(response, list, "购买详情数据");
    }

    /**
     * 获取购买详情详细信息
     */
    @GetMapping(value = "/{merchantOrderNumber}")
    public AjaxResult getInfo(@PathVariable("merchantOrderNumber") String merchantOrderNumber)
    {
        return success(shoppingPurchaseService.selectShoppingPurchaseByMerchantOrderNumber(merchantOrderNumber));
    }

    /**
     * 新增购买详情
     */
    @Log(title = "购买详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShoppingPurchase shoppingPurchase)
    {
        return toAjax(shoppingPurchaseService.insertShoppingPurchase(shoppingPurchase));
    }

    /**
     * 修改购买详情
     */
    @Log(title = "购买详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShoppingPurchase shoppingPurchase)
    {
        return toAjax(shoppingPurchaseService.updateShoppingPurchase(shoppingPurchase));
    }

    /**
     * 删除购买详情
     */
    @Log(title = "购买详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{merchantOrderNumbers}")
    public AjaxResult remove(@PathVariable String[] merchantOrderNumbers)
    {
        return toAjax(shoppingPurchaseService.deleteShoppingPurchaseByMerchantOrderNumbers(merchantOrderNumbers));
    }
}
